home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / fs / ioctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.4 KB  |  104 lines

  1. /*
  2.  *  linux/fs/ioctl.c
  3.  *
  4.  *  Copyright (C) 1991, 1992  Linus Torvalds
  5.  *
  6.  * This file is subject to the terms and conditions of the GNU General Public
  7.  * License.  See the file README.legal in the main directory of this archive
  8.  * for more details.
  9.  */
  10.  
  11. #include <asm/segment.h>
  12.  
  13. #include <linux/sched.h>
  14. #include <linux/errno.h>
  15. #include <linux/string.h>
  16. #include <linux/stat.h>
  17. #include <linux/termios.h>
  18. #include <linux/fcntl.h> /* for f_flags values */
  19.  
  20. static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
  21. {
  22.     int error;
  23.     int block;
  24.  
  25.     switch (cmd) {
  26.         case FIBMAP:
  27.             if (filp->f_inode->i_op == NULL)
  28.                 return -EBADF;
  29.                 if (filp->f_inode->i_op->bmap == NULL)
  30.                 return -EINVAL;
  31.             error = verify_area(VERIFY_WRITE,(void *) arg,4);
  32.             if (error)
  33.                 return error;
  34.             block = get_fs_long((long *) arg);
  35.             block = filp->f_inode->i_op->bmap(filp->f_inode,block);
  36.             put_fs_long(block,(long *) arg);
  37.             return 0;
  38.         case FIGETBSZ:
  39.             if (filp->f_inode->i_sb == NULL)
  40.                 return -EBADF;
  41.             error = verify_area(VERIFY_WRITE,(void *) arg,4);
  42.             if (error)
  43.                 return error;
  44.             put_fs_long(filp->f_inode->i_sb->s_blocksize,
  45.                 (long *) arg);
  46.             return 0;
  47.         case FIONREAD:
  48.             error = verify_area(VERIFY_WRITE,(void *) arg,4);
  49.             if (error)
  50.                 return error;
  51.             put_fs_long(filp->f_inode->i_size - filp->f_pos,
  52.                 (long *) arg);
  53.             return 0;
  54.     }
  55.     if (filp->f_op && filp->f_op->ioctl)
  56.         return filp->f_op->ioctl(filp->f_inode, filp, cmd,arg);
  57.     return -EINVAL;
  58. }
  59.  
  60.  
  61. asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
  62. {    
  63.     struct file * filp;
  64.     int on;
  65.  
  66.     if (fd >= NR_OPEN || !(filp = current->filp[fd]))
  67.         return -EBADF;
  68.     switch (cmd) {
  69.         case FIOCLEX:
  70.             FD_SET(fd, ¤t->close_on_exec);
  71.             return 0;
  72.  
  73.         case FIONCLEX:
  74.             FD_CLR(fd, ¤t->close_on_exec);
  75.             return 0;
  76.  
  77.         case FIONBIO:
  78.             on = get_fs_long((unsigned long *) arg);
  79.             if (on)
  80.                 filp->f_flags |= O_NONBLOCK;
  81.             else
  82.                 filp->f_flags &= ~O_NONBLOCK;
  83.             return 0;
  84.  
  85.         case FIOASYNC: /* O_SYNC is not yet implemented,
  86.                   but it's here for completeness. */
  87.             on = get_fs_long ((unsigned long *) arg);
  88.             if (on)
  89.                 filp->f_flags |= O_SYNC;
  90.             else
  91.                 filp->f_flags &= ~O_SYNC;
  92.             return 0;
  93.  
  94.         default:
  95.             if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
  96.                 return file_ioctl(filp,cmd,arg);
  97.  
  98.             if (filp->f_op && filp->f_op->ioctl)
  99.                 return filp->f_op->ioctl(filp->f_inode, filp, cmd,arg);
  100.  
  101.             return -EINVAL;
  102.     }
  103. }
  104.